<template>
  <div>
    <div v-if="cars.length">
      <van-card
        v-for="v in cars"
        :key="v.id"
        :price="v.price.toFixed(2)"
        :desc="v.desc"
        :title="v.title"
        :thumb="v.url"
        :num="v.count"
      />

      {{ totalPrice }}
    </div>
    <div v-else style="text-align:center">
      购物车为空， 去买点东西把
    </div>

  
  </div>
</template>

<script>
export default {
  name: 'Car',
  data() {
    return {
      cars: JSON.parse(localStorage.getItem('cars')) || []
    }
  },
  computed: {
    totalPrice() {
      let price = 0;
      this.cars.forEach(v => {
        price += v.price * v.count
      })
      return price
    }
  }
}
</script>